<template>
  <div class="contarner-page" @click.stop="showLanguageHandel">
    <page-header ref="languageRef"></page-header>
    <main>
      <div class="background">
        <div class="content flex_ccenter">
          <h1 class="alt-title container-tt">
            {{ articleObj.articleTitle }}
          </h1>
          <div class="uname flex_">
            by
            <nuxt-link :to="`/blog/author${articleObj.authorUrl}`">
              <div class="name" @click.stop="StorageAuthorId">
                {{ articleObj.author }}
              </div>
            </nuxt-link>
          </div>
          <div class="info-box flex_">
            <div class="info1">
              Classified Topic：
              <nuxt-link :to="`/blog/topics/${articleObj.type}`">
                {{ articleObj.type }}
              </nuxt-link>
            </div>
            <div class="info2"></div>
            <div class="info3">Update：{{ articleObj.shortUpTime }}</div>
            <div class="info2"></div>
            <div class="info4">{{ articleObj.reTime }} min read</div>
          </div>
        </div>
      </div>
      <div class="container page_content">
        <div class="blog-content">
          <div class="flex_content container-tt">
            <div class="sticky-box flex_ container-tt">
              <div class="navigation-box" v-if="isShowSticky">
                <div class="navigation" :class="{ stickyNav: sticky }">
                  <div class="nav-title">Contents</div>
                  <div
                    :key="k"
                    v-for="(item, k) in navigationList"
                    @click.prevent="scrollTo(item.id)"
                    class="navigation-item shou"
                    :class="{ 'is-active': activeElement == item.id }"
                  >
                    {{ item.text }}
                  </div>
                </div>
              </div>
              <div style="width: 250px" v-else></div>
              <div class="richText">
                <div class="rich-img">
                  <img
                    :src="articleObj.imageUrl"
                    class="img"
                    :alt="articleObj.imageDescription"
                  />
                </div>
                <div class="rich-ccontent" v-html="articleObj.content"></div>
                <div class="faqs-content-article" v-if="faqList.length != 0">
                  <h3 class="faq-tit">FAQ</h3>
                  <div class="accordion">
                    <div
                      id="faq"
                      itemscope="itemscope"
                      itemtype="https://schema.org/FAQPage"
                    >
                      <div
                        itemprop="mainEntity"
                        itemscope="itemscope"
                        itemtype="https://schema.org/Question"
                        class="accordion-item"
                        :key="k"
                        v-for="(item, k) in faqList"
                      >
                        <h4 itemprop="name" class="accordion-title">
                          {{ item.qaTitle }}
                        </h4>
                        <div
                          itemprop="acceptedAnswer"
                          itemscope=""
                          itemtype="https://schema.org/Answer"
                        >
                          <div
                            itemprop="text"
                            class="accordion-text f-16 c-ccc fw400"
                          >
                            {{ item.qaContent }}
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="share-content flex_between">
                  <div></div>
                  <div class="share flex_">
                    <div>share:</div>
                    <a :href="facebook" target="_blank">
                      <img
                        src="@/static/share/facebook.svg"
                        class="img"
                        alt="facebook"
                      />
                      facebook
                    </a>
                    <a :href="twitter" target="_blank">
                      <img
                        src="@/static/share/twitter.svg"
                        class="img"
                        alt="twitter"
                      />
                      twitter
                    </a>
                    <a :href="linkedin" target="_blank">
                      <img
                        src="@/static/share/linkedin.svg"
                        class="img"
                        alt="linkedin"
                      />
                      linkedin
                    </a>
                  </div>
                </div>
                <div class="auther-info-box flex_">
                  <div class="">
                    <img class="img" :src="articleObj.authorPortrait" alt="" />
                  </div>
                  <div class="introduction flex_column">
                    <div class="col1">Article by</div>
                    <div class="col2 shou">
                      <nuxt-link :to="`/blog/author${articleObj.authorUrl}`">
                        {{ articleObj.author }}
                      </nuxt-link>
                    </div>
                    <div class="col4">{{ articleObj.position }}</div>
                    <div class="col3">{{ articleObj.authorDescription }}</div>
                  </div>
                </div>
                <div class="read-more" v-if="dataList.length != 0">
                  <div class="r-tit">Read More</div>
                  <div class="list flex_between">
                    <div
                      class="item shou"
                      :key="k"
                      v-for="(item, k) in dataList"
                    >
                      <nuxt-link :to="`/blog${item.url}`">
                        <div class="cover">
                          <img
                            :src="item.imageUrl"
                            class="img"
                            :alt="item.imageDescription"
                          />
                        </div>
                      </nuxt-link>
                      <nuxt-link :to="`/blog${item.url}`">
                        <div class="list-title">
                          {{ item.articleTitle }}
                        </div>
                      </nuxt-link>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
     
    </main>
    <footer>
        <div class="container page_content">
          <div class="footer-content">
            <div class="footer-link">
              <div class="row flex_between">
                <div class="col-12">
                  <div class="link-label">Tools</div>
                  <ul class="list-unstyled c-ccc f-16">
                    <li @click="goToTools('mp3')">
                      <nuxt-link to="/download-tiktok-mp3"
                        >Download TikTok MP3</nuxt-link
                      >
                    </li>
                    <li @click="goToTools('story')">
                      <nuxt-link to="/download-tiktok-story"
                        >Download TikTok Story</nuxt-link
                      >
                    </li>
                    <li>
                      <nuxt-link to="/save-tiktok-videos-without-posting">
                        How to save tiktok videos without posting
                      </nuxt-link>
                    </li>
                  </ul>
                </div>
                <div class="col-6">
                  <div class="link-label">Company</div>
                  <ul class="list-unstyled c-ccc f-16">
                    <li>
                      <nuxt-link to="/contact"> Contact </nuxt-link>
                    </li>
                    <li>
                      <nuxt-link to="/blog"> Blog </nuxt-link>
                    </li>
                  </ul>
                </div>
                <div class="col-6">
                  <div class="link-label">Legal</div>
                  <ul class="list-unstyled c-ccc f-16">
                    <li>
                      <nuxt-link to="/terms-of-use">
                        Terms of Service
                      </nuxt-link>
                    </li>
                    <li>
                      <nuxt-link to="/privacy-policy">
                        Privacy Policy
                      </nuxt-link>
                    </li>
                  </ul>
                </div>
              </div>
            </div>
            <div class="copyright flex_ccenter">
              <div class="c-ccc f-16">
                ©savinginsta.Com {{ new Date().getFullYear() }} All Rights
                Reserved.
              </div>
            </div>
          </div>
        </div>
      </footer>
  </div>
</template>
          <script>
import { handleClick } from "@/plugins/Firebase.js";
import { mapState, mapGetters, mapMutations } from "vuex";
import CryptoJS from "crypto-js";
import { encryptUrl, decryptUrl } from "~/utils/encryption";
export default {
  head() {
    return {
      htmlAttrs: {
        lang: "en",
      },
      bodyAttrs: {
        "data-lang": "en",
      },
      title: this.myTitle,
      script: this.myScript,
      meta: [
        {
          name: "viewport",
          content:
            "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no",
        },
        { name: "robots", content: "index, follow" },
        { name: "revisit-after", content: "1 days" },
        {
          name: "description",
          content: this.myDescription,
        },
        {
          itemprop: "name",
          content: this.myTitle,
        },
        { name: "author", content: this.authorName },
        { property: "og:locale", content: "en" },
        { itemprop: "image", content: this.myHeadImage },
        { name: "twitter:card", content: "summary" },
        { name: "twitter:title", content: this.myTitle },
        { name: "twitter:description", content: this.myDescription },
        {
          name: "twitter:image",
          content: this.myHeadImage,
        },
        { name: "twitter:site", content: "savinginsta" },
        { property: "og:title", content: this.myTitle },
        { property: "og:type", content: "article" },
        { property: "og:image", content: this.myHeadImage },
        { property: "og:description", content: this.myDescription },
        { property: "og:site_name", content: this.myArticleTitle },
        { name: "google", content: "notranslate" },
      ],
      link: this.myLinks,
    };
  },
  data() {
    return {
      isShowSticky: true,
      loading: false,
      myLinks: [
        // Favicons
        {
          rel: "shortcut icon",
          href: "/static/logo/favicon.png",
          sizes: "512x512",
        },
        {
          rel: "apple-touch-icon",
          href: "/static/logo/favicon.png",
          sizes: "192x192",
        },
      ],
      dataList: [],
      articleObj: {},
      location: null,
      initialTop: 633, // 初始顶部的距离
      sticky: false, // 是否吸顶
      contentTxt: "",
      dloading: false,
      showAppRight: false,
      showLanguage: false,
      Language: "en_GB",
      faqList: [],
      navigationList: [],
      activeElement: null,
      openBtn: false,
      openBtnApp: false,
      list1: [
        "en", // 英语
        "id", // 印度尼西亚语
        "vn", // 越南语
        "ms", // 马来语
        "jv", // 爪哇语
        "cs", // 捷克语
        "es", // 西班牙语
        "fr", // 法语
        "de", // 德语
        "it", // 意大利语
        "hu", // 匈牙利语
        "nl", // 荷兰语
        "pl", // 波兰语
        "pt", // 葡萄牙语
        "ro", // 罗马尼亚语
        "th", // 泰语
        "tr", // 土耳其语
        "el", // 希腊语
        "uk", // 乌克兰语
        "ru", // 俄语
        "ar", // 阿拉伯语
        "ko", // 韩语
        "ja", // 日语
      ],
      list: [
        "English", // 英语
        "Indonesia", // 印度尼西亚语
        "Tiếng Việt", // 越南语
        "Malaysia", // 马来语
        "Basa Jawa", // 爪哇语
        "Čeština", // 捷克语
        "Español", // 西班牙语
        "Français", // 法语
        "German", // 德语
        "Italian", // 意大利语
        "Magyar", // 匈牙利语
        "Nederlands", // 荷兰语
        "Polish", // 波兰语
        "Português", // 葡萄牙语
        "Română", // 罗马尼亚语
        "Thailand", // 泰语
        "Turkish (Turkey)", // 土耳其语
        "Ελληνικά", // 希腊语
        "украї́нська мо́ва", // 乌克兰语
        "Русский", // 俄语
        "عَرَبِيّ", // 阿拉伯语
        "한국어", // 韩语
        "日本語", // 日语
      ],
    };
  },
  async asyncData({ env, route, error, req }) {
    let location;
    // 检查是否在服务器上下文中
    if (process.server && req) {
      location = "https://savinginsta.com" + req.url;
    }

    // 其余变量初始化
    let authorObj = {};
    let authorList = [];
    let dataList = [];
    let articleObj = {};
    let authorName = "";
    let myTitle = "";
    let myDescription = "";
    let myArticleTitle = "";
    let myHeadImage = "";
    let myScript = [];
    let imagesList = [];
    // ...其余数据获取逻辑，例如获取作者详情和文章列表

    // 获取文章详细信息的逻辑
    const articleId = route.path.replace("/blog", ""); // 使用 route.params 获取动态路由参数
    const articleDetailResult = encryptUrl(
      JSON.stringify({
        id: articleId,
        packageName: "WebIns",
      }),
      env
    );

    try {
      // ...组合所有 Promise.all 中的请求
      // 获取文章详细信息的请求
      const articleDetailResponse = await fetch(
        "https://savinginsta.com/js/a/api/cms/web/articleDetailById",
        {
          method: "POST",
          body: JSON.stringify({ condition: articleDetailResult }),
          headers: {
            "Content-Type": "application/json",
          },
        }
      );

      if (!articleDetailResponse.ok) {
        throw new Error("Error fetching article details");
      }

      const articleDetailData = await articleDetailResponse.json();

      // 判断并处理文章详情数据
      if (articleDetailData.code !== 200) {
        error({
          statusCode: 404,
          message: "Post not found",
        });
        return { location, authorObj, authorList, dataList, articleObj }; // 提前返回以中断函数执行
      }

      const decryptedData = await decryptUrl(articleDetailData.data, env);
      const res = JSON.parse(decryptedData);
      articleObj = { ...res, location }; // 此处我们结合文章数据和地址信息
      authorName = articleObj.author;
      myTitle = articleObj.pageTitle;
      myDescription = articleObj.pageDescription;
      myArticleTitle = articleObj.articleTitle;
      myHeadImage = articleObj.imageUrl;
      if (articleObj.imagesList) {
        imagesList = articleObj.imagesList;
      }
      imagesList.push(articleObj.imageUrl);
      myScript = [
        {
          json: {
            "@context": "https://schema.org",
            "@type": "NewsArticle",
            headline: articleObj.articleTitle, //文章标题
            image: imagesList,
            datePublished: articleObj.createTime, // 发布时间
            dateModified: articleObj.updateTime, // 更新时间
            author: {
              "@type": "Person",
              name: articleObj.author, // 作者名
              url: "https://savinginsta.com/blog/author" + articleObj.authorUrl, //作者详情
            },
            publisher: {
              "@type": "Organization",
              name: "savinginsta",
              logo: {
                "@type": "ImageObject",
                url: "https://savinginsta.com/static/logo.png",
              },
            },
          },
          type: "application/ld+json",
        },
        {
          json: {
            "@context": "https://schema.org",
            "@type": "BreadcrumbList",
            itemListElement: [
              {
                "@type": "ListItem",
                position: 1,
                name: "Instagram downloader",
                item: "https://savinginsta.com/",
              },
              {
                "@type": "ListItem",
                position: 2,
                name: "blog",
                item: "https://savinginsta.com/blog",
              },
              {
                "@type": "ListItem",
                position: 3,
                name: articleObj.articleTitle, //取值文章标题
              },
            ],
          },
          type: "application/ld+json",
        },
      ];
    } catch (error) {
      console.error("asyncData error:", error);
      // 如果需要错误处理，可以使用 error 函数
      error({ statusCode: 500, message: "Internal Server Error" });
    }

    // 返回一个对象，该对象将合并到组件实例的数据中
    return {
      location,
      authorObj,
      authorList,
      dataList,
      articleObj,
      authorName,
      myTitle,
      myDescription,
      myArticleTitle,
      myHeadImage,
      myScript,
      imagesList,
    };
  },

  mounted() {
    window.addEventListener("scroll", this.checkStickiness);
    window.addEventListener("scroll", this.findActiveElement);
    window.addEventListener("scroll", this.handleScroll, false);
    this.checkStickiness();
    this.getFaqList(this.articleObj.id);
    this.getCateArticleList(this.articleObj.typeId);
    this.getform();
    // this.getArticleDtl();
  },
  beforeDestroy() {
    window.removeEventListener("scroll", this.checkStickiness);
    window.removeEventListener("scroll", this.findActiveElement);
    window.removeEventListener("scroll", this.handleScroll, false);
  },
  computed: {
    ...mapGetters(["language"]),
    current() {
      return this.list1.findIndex((x) => x == this.language);
    },
    path() {
      if (this.$route.path.length < 2) {
        return "en";
      } else {
        return this.$route.path.substring(1, 3);
      }
    },
    email() {
      return (
        "mailto:?subject=" +
        this.articleObj.articleTitle +
        "&body=" +
        encodeURIComponent(this.location)
      );
    },
    facebook() {
      return (
        "https://www.facebook.com/sharer/sharer.php?u=" +
        encodeURIComponent(this.location) +
        "&src=sdkpreparse"
      );
    },
    twitter() {
      return (
        "https://twitter.com/intent/tweet?text=" +
        this.articleObj.articleDescription +
        "&url=" +
        encodeURIComponent(this.location)
      );
    },
    pinterest() {
      return (
        "http://pinterest.com/pin/create/button/?url=" +
        encodeURIComponent(this.location) +
        "&media=" +
        this.articleObj.imageUrl +
        "&description=" +
        this.articleObj.articleDescription
      );
    },
    linkedin() {
      return (
        // "https://www.linkedin.com/shareArticle?mini=true&url=" +
        // encodeURIComponent(this.location) +
        // "&title=" +
        // this.articleObj.articleTitle +
        // "&summary=" +
        // this.articleObj.articleDescription
        "https://uk.linkedin.com/in/london-seo-consultant-chris-haines"
      );
    },
  },
  methods: {
    handleScroll() {
      // 获取元素距离顶部的距离
      const authorInfoBox = document.querySelector(".auther-info-box");
      const boundingClientRect = authorInfoBox.getBoundingClientRect();

      // 当元素的顶部距离小于等于0（在窗口顶部或已经滚动到之上）
      if (boundingClientRect.top <= 150) {
        this.isShowSticky = false;
      } else {
        this.isShowSticky = true;
      }
    },
    ...mapMutations(["setLanguage"]),
    setLanguageHandel(lang) {
      this.setLanguage(lang);
    },
    handleClickPasted() {
      if (!navigator.clipboard) {
        console.log("Clipboard API not available");
        return;
      }
      navigator.clipboard
        .readText()
        .then((text) => {
          this.input = text;
        })
        .catch((err) => {
          console.error("Failed to read clipboard contents: ", err);
        });
    },
    currentPath(k) {
      if (this.list1[k] == "en") {
        return "https://savinginsta.com/";
      } else {
        return "https://savinginsta.com/" + this.list1[k];
      }
    },
    changeLanguage(event, item, k) {
      event.preventDefault(); // 抑制默认的链接行为
      localStorage.setItem("language", this.list1[k]);
      this.setLanguage(this.list1[k]);
      this.openBtn = false;
      this.$nextTick(() => {
        window.location.href = this.currentPath(k);
      });
    },
    changeOpenBtn() {
      this.openBtn = !this.openBtn;
    },
    closeApp() {
      this.openBtnApp = !this.openBtnApp;
    },
    close() {
      this.openBtn = false;
      this.openBtnApp = false;
    },

    showLanguageHandel() {
      this.openBtn = false;
      this.openBtnApp = false;
    },
    getFjson() {
      this.myScript = [
        {
          json: {
            "@context": "https://schema.org",
            "@type": "NewsArticle",
            headline: this.articleObj.articleTitle, //文章标题
            image: this.imagesList,
            datePublished: this.articleObj.createTime, // 发布时间
            dateModified: this.articleObj.updateTime, // 更新时间
            author: {
              "@type": "Person",
              name: this.articleObj.author, // 作者名
              url:
                "https://savinginsta.com/blog/author" +
                this.articleObj.authorUrl, //作者详情
            },
            publisher: {
              "@type": "Organization",
              name: "savinginsta",
              logo: {
                "@type": "ImageObject",
                url: "https://savinginsta.com/static/logo.png",
              },
            },
          },
          type: "application/ld+json",
        },
        {
          json: {
            "@context": "https://schema.org",
            "@type": "BreadcrumbList",
            itemListElement: [
              {
                "@type": "ListItem",
                position: 1,
                name: "Instagram downloader",
                item: "https://savinginsta.com/",
              },
              {
                "@type": "ListItem",
                position: 2,
                name: "blog",
                item: "https://savinginsta.com/blog",
              },
              {
                "@type": "ListItem",
                position: 3,
                name: this.articleObj.articleTitle, //取值文章标题
              },
            ],
          },
          type: "application/ld+json",
        },
      ];
    },

    getform() {
      this.imagesList = [];
      this.imagesList.push(this.articleObj.imageUrl);
      let that = this;
      // 先解析HTML字符串
      var parser = new DOMParser();
      var doc = parser.parseFromString(this.articleObj.content, "text/html");
      // 获取所有h1和h2元素的数组
      var headings = Array.from(doc.querySelectorAll("h2"));
      var h1s = Array.from(doc.querySelectorAll("h1"));
      var hs = Array.from(doc.querySelectorAll("h3,h4,h5,h6"));
      var ps = Array.from(doc.querySelectorAll("p"));
      ps.forEach((x) => {
        x.classList.add("article-p");
      });
      var as = Array.from(doc.querySelectorAll("a"));
      as.forEach((a) => {
        a.classList.add("article-a");
      });
      // 遍历所有的h1和h2
      let idCounter = 1;
      let toc = []; // 用于存放提取的文本内容和id，用于生成侧边导航条目
      var images = doc.querySelectorAll("img");

      // 遍历图片并修改样式
      images.forEach((img) => {
        this.imagesList.push(img.src);
        // img.style.maxWidth = "100%";
        // img.style.height = "auto";
        // img.style.margin = "10px 0";
        // img.style.marginLeft = "auto";
        // img.style.marginRight = "auto";
        img.classList.add("custom-image");
      });
      h1s.forEach((h1) => {
        h1.classList.add("article-h1");
      });
      hs.forEach((h) => {
        h.classList.add("article-h");
      });
      headings.forEach((heading) => {
        heading.classList.add("article-h2");
        // 添加唯一id
        heading.id = "heading-id" + idCounter++;
        // 提取文本内容
        let textContent = heading.textContent;
        // switch (heading.tagName) {
        //   case "H1":
        //     heading.style.margin = "40px 0";
        //     heading.style.fontSize = "50px";
        //     heading.style.fontWeight = "bold";
        //     break;
        //   case "H2":
        //     heading.style.margin = "40px 0px";
        //     heading.style.fontSize = "28px";
        //     heading.style.fontWeight = "bold";
        //     break;
        //   case "H3":
        //     heading.style.margin = "30px 0";
        //     heading.style.fontSize = "20px";
        //     heading.style.fontWeight = "500";
        //     break;
        //   case "H4":
        //     heading.style.margin = "30px 0";
        //     heading.style.fontSize = "20px";
        //     heading.style.fontWeight = "500";
        //     break;
        //   case "H5":
        //     heading.style.margin = "30px 0";
        //     heading.style.fontSize = "20px";
        //     heading.style.fontWeight = "500";
        //     break;
        //   case "H6":
        //     heading.style.margin = "30px 0";
        //     heading.style.fontSize = "20px";
        //     heading.style.fontWeight = "500";
        //     break;

        //   default:
        //     break;
        // }
        // 存储到toc数组中，和它的id一起
        toc.push({
          id: heading.id,
          text: textContent,
        });
      });
      // 打印toc的内容
      this.navigationList = toc;
      setTimeout(() => {
        this.articleObj.content = doc.documentElement.outerHTML;
        this.getFjson();
      });
    },
    findActiveElement() {
      let scrollY = window.pageYOffset;
      let nearestElement = null;
      let nearestDistance = Infinity;

      this.navigationList.forEach((item) => {
        let element = document.getElementById(item.id);
        if (element) {
          let distance = Math.abs(element.getBoundingClientRect().top);

          if (distance < nearestDistance) {
            nearestDistance = distance;
            nearestElement = item.id;
          }
        }
      });

      if (nearestElement !== this.activeElement) {
        this.activeElement = nearestElement;
      }
    },
    getCateArticleList(typeid) {
      let that = this;
      let result = this.encryptUrl(
        JSON.stringify({
          pageNo: 1,
          pageSize: 9999,
          typeId: typeid,
          packageName: "WebIns",
        })
      );
      fetch("https://savinginsta.com/js/a/api/cms/web/listData", {
        method: "POST",
        body: JSON.stringify({
          condition: result,
        }),
        headers: {
          "Content-Type": "application/json",
        },
      }).then((response) => {
        response.json().then(async (data) => {
          data = await this.decryptUrl(data.data);
          let res = JSON.parse(data);
          if (res.list.length == 0) return;
          that.dataList = res.list
            .filter((item) => item.id != that.articleObj.id)
            .slice(0, 4); // Add .slice(0, 5) here
        });
      });
    },
    encryptUrl(input) {
      let CIPHER_ALGORITHM = "DES-CBC";
      let IV_SIZE = 8;
      let KEY_PWD = process.env.DES_CMS_KEY;
      try {
        const keyBytes = CryptoJS.enc.Utf8.parse(KEY_PWD);
        const inputBytes = CryptoJS.enc.Utf8.parse(input);
        const ivBytes = CryptoJS.lib.WordArray.random(IV_SIZE);
        const encrypted = CryptoJS.DES.encrypt(inputBytes, keyBytes, {
          iv: ivBytes,
          mode: CryptoJS.mode.CBC,
          padding: CryptoJS.pad.Pkcs7,
        });
        const ciphertext = ivBytes.concat(encrypted.ciphertext);
        return ciphertext.toString();
      } catch (error) {
        console.error(error);
        return null;
      }
    },
    decryptUrl(cipherText) {
      let CIPHER_ALGORITHM = "DES-CBC";
      let IV_SIZE = 8;
      let KEY_PWD = process.env.DES_CMS_KEY;
      try {
        let keyBytes = CryptoJS.enc.Utf8.parse(
          KEY_PWD.padEnd(CIPHER_ALGORITHM === "DES-CBC" ? 8 : 16)
        );
        let ivBytes = { iv: CryptoJS.enc.Hex.parse(process.env.DES_CMS_IV) }; // 如果使用CBC模式，需要一个初始化向量iv，这里是空向量
        let decrypted = CryptoJS.DES.decrypt(
          { ciphertext: CryptoJS.enc.Hex.parse(cipherText) },
          keyBytes,
          ivBytes
        );
        return decrypted.toString(CryptoJS.enc.Utf8);
      } catch (e) {
        console.error(e);
        return null;
      }
    },
    StorageAuthorId() {
      localStorage.setItem("AuthorId", this.articleObj.authorId);
    },
    getFaqList(id) {
      let that = this;
      let result = this.encryptUrl(
        JSON.stringify({
          articleId: id,
          packageName: "WebIns",
        })
      );
      fetch("https://savinginsta.com/js/a/api/cms/qa/qaByArticleId", {
        method: "POST",
        body: JSON.stringify({
          condition: result,
        }),
        headers: {
          "Content-Type": "application/json",
        },
      }).then((response) => {
        response.json().then(async (data) => {
          if (data.code == 200) {
            data = await this.decryptUrl(data.data);
            let res = JSON.parse(data);
            that.faqList = res;
          } else {
            that.faqList = [];
          }
        });
      });
    },
    scrollTo(id) {
      const element = document.getElementById(id);
      if (element) {
        const rect = element.getBoundingClientRect();
        window.scrollTo({
          top: rect.top + window.scrollY - 100,
          behavior: "smooth",
        });
      }
    },
    getArticleDtl() {
      this.loading = true;
      let id = this.$route.path.replace("/blog", "");
      let that = this;
      let result = this.uki(
        JSON.stringify({
          id: id,
          packageName: "WebIns",
        })
      );
      fetch("https://savinginsta.com/js/a/api/cms/web/articleDetailById", {
        method: "POST",
        body: JSON.stringify({
          condition: result,
        }),
        headers: {
          "Content-Type": "application/json",
        },
      }).then((response) => {
        response.json().then(async (data) => {
          this.loading = false;

          if (data.code != 200) {
            this.$nuxt.error({
              statusCode: 404,
              message: "Post not found",
            });
          } else {
            data = await this.decryptUrl(data.data);
            let res = JSON.parse(data);
            this.getFaqList(res.id);
            let date = new Date(res.updateTime);
            let month = date.toLocaleString("en-US", { month: "short" });
            let day = date.getDate();
            let year = date.getFullYear();
            res.updateTime = month + " " + day + ", " + year;
            that.articleObj = res;
            // navigationList
            that.getCateArticleList(res.typeId);
            that.updateTitleAndDescription(
              res.pageTitle,
              res.pageDescription,
              res.author,
              res.articleTitle,
              res.imageUrl
            );

            // 先解析HTML字符串
            var parser = new DOMParser();
            var doc = parser.parseFromString(res.content, "text/html");
            // 获取所有h1和h2元素的数组
            var headings = Array.from(
              doc.querySelectorAll("h1, h2,h3,h4,h5,h6")
            );
            var ps = Array.from(doc.querySelectorAll("p"));

            ps.forEach((x) => {
              x.style.margin = "10px 0";
            });
            // 遍历所有的h1和h2
            let idCounter = 1;
            let toc = []; // 用于存放提取的文本内容和id，用于生成侧边导航条目
            var images = doc.querySelectorAll("img");

            // 遍历图片并修改样式
            images.forEach((img) => {
              img.style.maxWidth = "100%";
              img.style.height = "auto";
              img.style.margin = "10px 0";
              img.style.marginLeft = "auto";
              img.style.marginRight = "auto";
            });
            headings.forEach((heading) => {
              // 添加唯一id
              heading.id = "heading-id" + idCounter++;
              // 提取文本内容
              let textContent = heading.textContent;
              switch (heading.tagName) {
                case "H1":
                  heading.style.margin = "40px 0";
                  break;
                case "H2":
                  heading.style.margin = "24px 0px";
                  break;
                case "H3":
                  heading.style.margin = "18px 0";
                  break;
                case "H4":
                  heading.style.margin = "10px 0";
                  break;
                case "H5":
                  heading.style.margin = "10px 0";
                  break;
                default:
                  break;
              }
              // 存储到toc数组中，和它的id一起
              toc.push({
                id: heading.id,
                text: textContent,
              });
            });
            // 打印toc的内容
            that.navigationList = toc;
            that.articleObj.content = doc.documentElement.outerHTML;
            // 导航块应当可以使用toc数组来构建。在点击对应的导航项时，滚动到对应ID的位置即可。
          }
        });
      });
    },
    updateTitleAndDescription(
      newTitle,
      newDescription,
      authorName,
      myArticleTitle,
      myHeadImage
    ) {
      this.authorName = authorName;
      this.myTitle = newTitle;
      this.myDescription = newDescription;
      this.myArticleTitle = myArticleTitle;
      this.myHeadImage = myHeadImage;

      this.myLinks.push({
        rel: "canonical",
        href: "https://savinginsta.com" + this.$route.path,
      });
    },
    checkStickiness() {
      if (window.scrollY >= this.initialTop) {
        this.sticky = true;
      } else {
        this.sticky = false;
      }
    },
    getPageNo(newPageNo) {
      this.pageNo = newPageNo;
      // 你也可以在这里加入更多的逻辑
      // 例如，你可能希望用新的页面编号来发送一个新的API请求
    },
    goToApp(e, type) {
      let url = "";
      switch (type) {
        case "video":
          url = "";
          break;
        case "mp3":
          url = "/download-tiktok-mp3";
          break;
        default:
          url = "/download-tiktok-story";
      }
      if (this.language !== "en") {
        url = `/${this.language}${url}`;
      } else if (this.language == "en" && type == "video") {
        url = `/`;
      }
      this.$router.push(url);
      // 切换页面 action_page_switch
      handleClick("action_page_switch", {
        site: type,
        from: "top",
      });
    },
    goToTop(type) {
      // 切换页面 action_page_switch
      handleClick("action_page_switch", {
        site: type,
        from: "top",
      });
    },
    goToTools(type) {
      // 切换页面 action_page_switch
      handleClick("action_page_switch", {
        site: type,
        from: "tools",
      });
    },
    changeFaqItemOpen(item, k) {
      item.isOpen = !item.isOpen;
    },
  },
};
</script>
<style lang="scss">
.custom-image {
  max-width: 100%;
  height: auto;
  margin: 30px 0;
  margin-left: auto;
  margin-right: auto;
}
.article-p {
  font-size: 18px;
  margin: 30px 0;
  font-weight: 400;
}
.article-h1 {
  margin: 40px 0;
  font-size: 50px;
  font-weight: bold;
}
.article-h2 {
  margin: 40px 0;
  font-size: 36px;
  font-weight: bold;
}
.article-h {
  margin: 30px 0;
  font-size: 26px;
  font-weight: 500;
}
.article-a {
  color: #04369f;
  font-weight: bold;
}
.article-a:hover {
  text-decoration: underline;
}
/* 隐藏滚动条 */
.navigation-box ::-webkit-scrollbar {
  width: 0.5em;
  background-color: transparent;
}

// ::-webkit-scrollbar-track {
//   background-color: transparent;
// }

// ::-webkit-scrollbar-thumb {
//   background-color: #5d636b;
//   border-radius: 0.5em;
// }

// ::-webkit-scrollbar-thumb:hover {
//   background-color: #555;
// }
 
.is-active {
  color: rgb(6, 74, 218) !important; // 换成你需要的颜色
  background-color: rgba(5, 74, 218, 0.06);
}
.sticky {
  position: fixed !important;
  top: 0px;
}
.stickyNav {
  position: fixed !important;
  top: 20px;
  width: 220px;
}
.header {
  background-color: #fff;

  .navbar {
    border-bottom: 1px solid #f2f0f7;
  }

  .container-tt {
    .nav_posi {
      position: relative;

      .language-content {
        position: absolute;
        right: 0px;
        top: 60px;
        padding: 6px 20px;
        padding-right: 0;
        padding-left: 34px;
        width: 327px;
        border-radius: 8px;
        border: 1px solid #d9d9d9;
        flex-wrap: wrap;
        background: #fff;
        z-index: 9999;

        .item {
          z-index: 9999;
          color: #000;
          font-size: 14px;
          width: 50%;
          margin: 12px 0;
        }

        .changeItem {
          color: #064ada;
          font-weight: 700;
        }
      }
    }

    .navbar-brand {
      padding: 14px 0;

      .img {
        width: 34px;
        height: 34px;
      }

      .projectName {
        font-size: 21px;
        font-weight: 600;
        color: #000;
        margin-left: 14px;
      }
    }

    .app-dropdown {
    }

    .navbar-collapse {
      position: relative;

      .dropdown {
        font-size: 14px;

        .dropdownImg {
          margin-left: 10px;
          width: 14px;
          height: 14px;
          background-image: url("~static/images/dropdown.webp");
          /* 使用 "~" 作为前缀可以更好地解析静态资源的路径 */
          background-size: 14px 14px;
          background-repeat: no-repeat;
        }

        .dropdownImg-up {
          margin-left: 10px;
          width: 14px;
          height: 14px;
          background-image: url("~static/images/dropdown-up.webp");
          background-size: 14px 14px;
          background-repeat: no-repeat;
        }
      }

      .dropdown-app {
        display: none;
      }
    }
  }
}
footer {
  background-color: #fafafa;

  .footer-content {
    padding: 50px 0 30px;

    .row {
      display: flex;
      flex-wrap: wrap;
      align-items: flex-start;

      .col-12 {
        flex: 0 0 auto;
        width: 33.33333333%;
      }

      .col-6 {
        flex: 0 0 auto;
        width: 33.33333333%;
      }

      .link-label {
        color: #222;
        font-weight: 700;
        font-size: 18px;
      }

      .list-unstyled {
        margin-top: 20px;
        list-style: none;
        color: #000;
        font-size: 14px;

        li {
          margin-bottom: 20px;
        }
      }
    }

    .copyright {
      margin-top: 40px;

      div {
        margin-top: 8px;
      }
    }
  }
}
.share-content-app {
  display: none;
}

.background {
  background-color: #5c31d6;
  padding: 50px 0;
  color: #fff;
  .content {
    margin-left: auto;
    margin-right: auto;
    padding: 0 80px;
    .cateImg {
      overflow: hidden;
      width: 120px;
      height: 120px;
      border-radius: 4px;
    }
    .alt-title {
      margin: 36px 0;
      font-size: 50px;
      font-weight: 700;
      text-align: center;
      max-width: 850px;
    }
    .uname {
      font-size: 18px;
      .name {
        text-decoration: underline;
        margin-left: 4px;
      }
    }
    .info-box {
      margin-top: 20px;
      font-size: 18px;
      .info2 {
        width: 5px;
        height: 5px;
        margin: 0 14px;
      }
    }
  }
}
.blog-content {
  flex: 1;
  .flex_content {
    position: initial;
    align-items: flex-start;
    .bread-crumbs {
      margin-left: auto;
      margin-right: auto;
      .bread {
        padding: 30px 0;
        width: 100%;
        background-color: #fff;
        z-index: 200;
      }
      .crumbs {
        color: #4a4a4a;
        font-size: 18px;
      }
      .right-disabled {
        margin: 0 10px;
        width: 24px !important;
        height: 24px !important;
        background-image: url("@/static/images/next-disabled.webp");
        background-size: 24px 24px;
        background-repeat: no-repeat;
      }
      .active {
        font-size: 18px;
      }
    }

    .sticky-box {
      align-items: flex-start;
      .navigation-box {
        margin-top: 20px;
        width: 220px;
        margin-right: 30px;

        .nav-title {
          font-size: 21px;
          font-weight: 700;
          padding: 20px;
          padding-top: 0;
          padding-left: 14px;
        }
        .navigation {
          overflow: auto;
          height: auto;
          max-height: calc(100vh - 300px) !important;
          padding: 20px 0;
          z-index: 99999;
          border-right: 1px solid #e7e7e7;

          .navigation-item {
            color: rgba(29, 33, 44, 0.5);
            font-size: 14px;
            padding: 6px 10px;
            line-height: 20px;
          }
        }
      }
      .richText {
        flex: 1;
        max-width: 670px;
        .share-content {
          .share {
            a {
              font-size: 0;
              .img {
                width: 24px;
                height: 24px;
                margin-left: 14px;
              }
            }
          }
        }
        .rich-img {
          overflow: hidden;
          width: 100%;
          height: 449px;
          border-radius: 12px;
          margin-top: 20px;
          margin-bottom: 30px;
          .img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
        }
        .faqs-content-article {
          margin-top: 20px;
          .faq-tit {
            font-size: 32px;
            font-weight: 700;
          }
          .accordion {
            margin-top: 30px;
            .accordion-item {
              margin-bottom: 40px;
              .accordion-title {
                color: #000;
                font-size: 26px;
                font-weight: 700;
              }
              .accordion-text {
                margin-top: 10px;
                font-size: 18px;
                color: #000;
              }
            }
          }
        }
        .app-box {
          width: 100%;
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          padding: 30px 24px;
          gap: 64px;
          margin-top: 24px;
          border-radius: 12px;
          background: rgba(6, 74, 218, 1);
          color: #fff;
          .app-box__info {
            text-align: left;
            font-size: 18px;
            h3 {
              margin-bottom: 20px;
            }
            a {
              color: #3ec6ff;
            }
          }
          .app-link {
            display: flex;
            align-items: center;
            gap: 16px;
            a {
              img {
                width: 154px;
                height: 48px;
              }
            }
          }
        }
        .read-more {
          margin-top: 30px;
          .r-tit {
            font-weight: 700;
            font-size: 32px;
            margin-bottom: 20px;
          }
          ul {
            list-style-type: none !important;
            list-style: none !important;
            li {
              margin-bottom: 8px;
              list-style: none !important;
              font-size: 16px;
              span {
                // text-decoration: underline;
                color: rgba(6, 74, 218, 1);
              }
            }
          }
          ul li::before {
            content: "•";
            font-size: 20px;
            color: rgba(6, 74, 218, 1);
            margin-right: 10px;
          }
          .list {
            flex-wrap: wrap;
            align-items: stretch;
            .item {
              width: 47%;
              margin-bottom: 30px;
              .cover {
                overflow: hidden;
                width: 100%;
                height: 164px;
                border-radius: 8px;
                object-fit: cover;
                .img {
                  object-fit: cover;
                  transition: transform 500ms;
                }
              }
              .cover:hover {
                .img {
                  transform: scale(1.1);
                }
              }
              .list-title {
                margin-top: 10px;
                font-size: 18px;
                font-weight: 700;
                color: #064ada;
              }
              .list-title:hover {
                text-decoration: underline;
              }
              .info {
                margin-top: 12px;
                font-size: 18px;
                .info_2 {
                  color: #064ada;
                  margin-left: 6px;
                }
                .info_3 {
                  width: 3px;
                  height: 3px;
                  background: #4a4a4a;
                  border-radius: 50%;
                  margin: 0 10px;
                }
                .info_4 {
                  color: #4a4a4a;
                }
              }
            }
          }
        }
      }
    }
  }
  .auther-info-box {
    margin-top: 30px;
    padding-top: 30px;
    margin-bottom: 40px;
    padding: 20px;
    background-color: #fafafa;
    .img {
      width: 150px;
      height: 150px;
      margin-right: 30px;
      object-fit: cover;
      border-radius: 50%;
    }
    .introduction {
      padding-top: 30px;
      .col1 {
        font-size: 16px;
      }
      .col2 {
        margin: 14px 0 0;
        font-size: 36px;
        font-weight: 700;
      }
      .col4 {
        margin: 0px 0 20px;
        font-weight: 700;
      }
      .col2:hover {
        text-decoration: underline;
      }
    }
  }
}
@media (max-width: 768px) {
  .auther-info-box {
    padding: 10px;
    background-color: #fafafa;
    display: flex;
    flex-direction: column;
    .img {
      width: 180px !important;
      height: 180px !important;
      object-fit: cover;
      border-radius: 4px;
    }
    .introduction {
      width: 100%;
      .col1 {
        margin-top: 10px;
        font-size: 16px;
      }
      .col2 {
        margin: 10px 0 10px 0 !important;
        font-size: 26px !important;
        font-weight: 700;
      }
      .col2:hover {
        text-decoration: underline;
      }
    }
  }
  .list {
    padding: 0;
    padding-top: 28px;
    padding-bottom: 10px;
    flex-wrap: wrap;
    align-items: stretch;
    .item {
      width: 100% !important;
      margin-bottom: 20px;
      .cover {
        overflow: hidden;
        width: 100%;
        height: 160px;
        border-radius: 16px;
        object-fit: cover;
        .img {
          object-fit: cover;
          transition: transform 500ms;
        }
      }
      .cover:hover {
        .img {
          transform: scale(1.1);
        }
      }
      .cate {
        margin: 10px 0;
        font-size: 16px;
        font-weight: 700;
        color: #f9224c;
      }
      .list-title {
        font-size: 18px;
        font-weight: 700;
      }
      .list-title:hover {
        text-decoration: underline;
      }
      .info {
        margin-top: 10px;
        font-size: 14px;
        .info_2 {
          margin-left: 6px;
          color: #064ada;
        }
        .info_3 {
          width: 3px;
          height: 3px;
          background: #4a4a4a;
          border-radius: 50%;
          margin: 0 10px;
        }
        .info_4 {
        }
      }
    }
  }
  .page_content {
    padding: 0 18px;
  }
  .container {
    .navbar-brand {
      padding: 10px 0 !important;
    }

    .navbar-collapse {
      .dropdown {
        display: none !important;

        .dropdownImg {
          margin-left: 10px;
          width: 20px;
          height: 20px;
          background-image: url("~static/images/dropdown.webp");
          background-size: 20px 20px;
          background-repeat: no-repeat;
        }

        .dropdownImg-up {
          margin-left: 10px;
          width: 20px;
          height: 20px;
          background-image: url("~static/images/dropdown-up.webp");
          background-size: 20px 20px;
          background-repeat: no-repeat;
        }
      }

      .dropdown-app {
        display: block !important;
        width: 24px !important;
        height: 24px !important;
        background-image: url("~static/images/drawer.webp");
        background-size: contain !important;
        background-repeat: no-repeat;
      }
    }

    .language-content {
      position: static !important;
      padding-top: 0px !important;
      padding-bottom: 10px;
      color: #433aff;
      font-size: 16px;
      font-weight: 400;
      flex-wrap: wrap;
      width: 100% !important;
      border: 0 !important;
      padding-left: 0 !important;

      .item {
        z-index: 9999;
        color: #1d212c;
        font-size: 14px;
        width: 50%;
        margin: 12px 0;
      }
    }
  }
  footer {
    background-color: #fafafa;

    .footer-content {
      padding: 30px 0 30px;

      .row {
        display: flex;
        flex-wrap: wrap;

        .col-12 {
          flex: 0 0 auto;
          width: 100%;
          margin-bottom: 14px;
        }

        .col-6 {
          flex: 0 0 auto;
          width: 50%;
        }

        .link-label {
          color: #222;
          font-weight: 700;
          font-size: 18px;
        }

        .list-unstyled {
          margin-top: 12px;
          list-style: none;
          color: #000;

          li {
            margin-bottom: 20px;
            font-size: 14px;
          }
        }
      }

      .copyright {
        margin-top: 40px;

        b {
          font-size: 14px !important;
        }

        div {
          margin-top: 8px;
          font-size: 14px !important;
        }
      }
    }
  }
  .sticky {
    position: relative !important;
  }
  .stickyNav {
    position: static !important;
    width: 100%;
  }
  .blog-content .flex_content .sticky-box .navigation-box {
    width: 100% !important;
  }
  .background {
    
    padding: 30px 0;
    color: #fff;
    .content {
      padding: 0 40px;
      .cateImg {
        overflow: hidden;
        width: 100px;
        height: 100px;
        border-radius: 4px;
      }
      .alt-title {
        margin: 16px 0;
        font-size: 30px;
        font-weight: 700;
        text-align: center;
      }
      .uname {
        font-size: 16px;
        .name {
          text-decoration: underline;
          margin-left: 4px;
        }
      }
      .info-box {
        margin-top: 20px;
        font-size: 14px;
        display: flex;
        flex-direction: column;
        .info2 {
          margin: 2px 0;
        }
      }
    }
  }
  .blog-content {
    flex: 1;
    .flex_content {
      position: initial;
      align-items: flex-start;
      .bread-crumbs {
        .bread {
          flex-wrap: wrap;
          padding: 14px 0;
          background-color: #fff;
          width: 100%;
        }
        .crumbs {
          color: rgba(29, 33, 44, 0.5);
          font-size: 14px;
          margin-bottom: 10px;
        }
        .right-disabled {
          margin: 0 10px;
          width: 24px !important;
          height: 24px !important;
          background-image: url("@/static/images/next-disabled.webp");
          background-size: 24px 24px;
          background-repeat: no-repeat;
          margin-bottom: 10px;
        }
        .active {
          font-size: 14px;
        }
      }
      .share-content-app {
        display: none;
        margin-bottom: 16px;
        .share {
          a {
            .img {
              width: 26px;
              height: 26px;
              margin-right: 20px;
            }
          }
        }
      }
      .sticky-box {
        display: flex !important;
        flex-direction: column !important;
        .navigation-box {
          display: none;
          width: 100%;
          .nav-title {
            font-weight: 700;
            font-size: 16px;
            padding: 10px;
          }
          .navigation {
            height: auto;
            border-radius: 12px;
            width: 100%;
            border: 0;
            .navigation-item {
              padding: 10px 14px;
              text-decoration: underline;
              color: rgba(29, 33, 44, 0.5);
            }
          }
        }
        .richText {
          width: 100%;
          max-width: 100%;
          padding-left: 0;
          .share-content {
            // display: none !important;
            .share {
              a {
                .img {
                  width: 24px;
                  height: 24px;
                  margin-left: 14px;
                }
              }
            }
          }
          .rich-img {
            overflow: hidden;
            width: 100%;
            height: 200px;
            border-radius: 12px;
            margin-top: 20px;
            margin-bottom: 30px;
            .img {
              width: 100%;
              height: 100%;
              object-fit: cover;
            }
          }
          .faqs-content-article {
            margin-top: 20px;
            .faq-tit {
              font-size: 24px;
              text-align: center;
              font-weight: 700;
              span {
                display: none;
              }
            }
            .accordion {
              margin-top: 30px;
              .accordion-item {
                margin-bottom: 24px;
                .accordion-title {
                  font-size: 18px;
                  font-weight: 700;
                }
                .accordion-text {
                  margin-top: 10px;
                  font-size: 16px;
                }
              }
            }
          }
          .app-box {
            width: 100%;
            padding: 20px 24px;
            margin-top: 24px;
            border-radius: 12px;
            background: rgba(6, 74, 218, 1);
            text-align: center;
            color: #fff;

            .app-box__info {
              text-align: center;
              h3 {
                font-size: 18px;
                margin-bottom: 20px;
              }
              a {
                color: #3ec6ff;
                font-size: 16px;
              }
            }
            .app-link {
              width: 100%;
              margin-top: 20px;
              display: flex;
              align-items: center;
              gap: 16px;
              a {
                width: 49%;

                img {
                  width: 100%;
                  height: 48px;
                }
              }
            }
          }
          .read-more {
            margin-top: 30px;
            .r-tit {
              font-weight: 700;
              font-size: 24px;
              margin-bottom: 0px;
            }
            ul {
              list-style-type: none !important;
              list-style: none !important;
              li {
                margin-bottom: 8px;
                list-style: none !important;
                font-size: 16px;
                span {
                  text-decoration: underline;
                  color: rgba(6, 74, 218, 1);
                }
              }
            }
            ul li::before {
              content: "•";
              font-size: 16px;
              color: rgba(6, 74, 218, 1);
            }
          }
        }
      }
    }
  }
}

@media (max-width: 992px) {
  .rich-img {
    height: 300px !important;
  }
  .blog-content .flex_content .sticky-box .navigation-box {
    width: calc((100vw - 992px) / 2 + 240px);
  }
  .stickyNav {
    position: fixed !important;
    top: 20px;
    width: calc((100vw - 992px) / 2 + 240px);
  }
}
@media (max-width: 768px) {
  .stickyNav {
    position: static !important;
    width: 100%;
  }
  .rich-img {
    height: 200px !important;
  }
}
@media (min-width: 1200px) {
  .rich-img {
    height: 370px !important;
  }
}
</style>